// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SETCommonImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.Hl7Exception;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.ST;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            ANYImpl, BLImpl, INTImpl

public abstract class SETCommonImpl extends ANYImpl
{

    public static final String RCS_ID = "$Header: SETCommonImpl.java 115.26 2005/07/15 11:45:50 anbindal noship $";
    protected Set mSet;

    public SETCommonImpl(Set set)
    {
        mSet = new HashSet();
        if(set == null)
        {
            throw ANYImpl.newNullException("SET", "constructor", "set");
        } else
        {
            mSet.addAll(set);
            return;
        }
    }

    public SETCommonImpl(CS cs)
    {
        super(true, cs);
        mSet = new HashSet();
    }

    protected SETCommonImpl()
    {
        mSet = new HashSet();
    }

    public BL isEmpty()
    {
        return BLImpl.valueOf(mSet.isEmpty());
    }

    public BL notEmpty()
    {
        return isEmpty().not();
    }

    public INT cardinality()
    {
        return INTImpl.valueOf(mSet.size());
    }

    public ST literal()
    {
        throw ANYImpl.newUnsupportedException("SET", "literal");
    }

    protected boolean equalsSet(Set set)
    {
        boolean flag = mSet.size() == set.size();
        for(Iterator iterator1 = set.iterator(); flag && iterator1.hasNext(); flag = mSet.contains(iterator1.next()));
        return flag;
    }

    public Set toSet()
    {
        return Collections.unmodifiableSet(mSet);
    }

    public Iterator iterator()
    {
        return mSet.iterator();
    }

    protected abstract boolean verifyItem(Object obj);

    protected boolean verifySet(Set set)
    {
        boolean flag = true;
        for(Iterator iterator1 = set.iterator(); flag && iterator1.hasNext(); flag = verifyItem(iterator1.next()));
        return flag;
    }

    public int hashCode()
    {
        int i = 17;
        if(isNull().isFalse())
            i += mSet.hashCode();
        return i;
    }

//    public XMLNode[] writeXML(XMLDocument xmldocument, String s)
//        throws Hl7Exception
//    {
//        int i = 0;
//        try
//        {
//            Vector vector = new Vector();
//            for(Iterator iterator1 = toSet().iterator(); iterator1 != null && iterator1.hasNext();)
//            {
//                Object obj = iterator1.next();
//                if((obj instanceof ANYImpl) && ((ANYImpl)obj).isNull().isFalse())
//                {
//                    i++;
//                    vector.add(((ANYImpl)obj).writeXML(xmldocument, s)[0]);
//                }
//            }
//
//            return (XMLNode[])vector.toArray(new XMLNode[i]);
//        }
//        catch(Exception exception)
//        {
//            throw new Hl7Exception(exception);
//        }
//    }
}
